package com.hualan.sfzy.controller.permission;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.model.entity.SystemUsers;
import com.hualan.sfzy.service.impl.permission.SystemUsersServiceImpl;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemUsers")
public class SystemUsersController {
    @Autowired
    private SystemUsersServiceImpl service;

    @GetMapping
    public Result find() {
        return Result.success(service.find());
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(service.findById(id));
    }

    @GetMapping("/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           SystemUsers systemUsers) {
        return Result.success(service.findPage(pageNum, pageSize,
                systemUsers));
    }

    @PostMapping
    public Result add(@RequestBody SystemUsers systemUsers) {
        return service.add(systemUsers) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Integer id) {

        return service.remove(id) > 0 ?Result.success() : Result.error();
    }

    @DeleteMapping
    public Result removeBatch(Integer[] ids) {

        return service.removeBatch(ids) > 0 ?Result.success() : Result.error();
    }

    @PutMapping
    public Result edit(@RequestBody SystemUsers systemUsers) {
        return service.edit(systemUsers) > 0 ? Result.success() : Result.error();
    }


}
